package com.ibeetl.blog.web;

import com.ibeetl.blog.model.Blog;
import com.ibeetl.blog.service.BlogService;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author GavinKing
 * @ClassName: IndexController
 * @Description:
 * @date 2018/11/17
 */
@Controller
public class IndexController {

    @Autowired
    private BlogService blogService;

    @GetMapping("/")
    public String index(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "8") Integer pageSize,
                        @RequestParam(value = "keyword", required = false) String keyword,
                        HttpServletRequest request){
        PageQuery<Blog> pageQuery = blogService.pageBlog(pageNumber, pageSize, keyword);
        request.setAttribute("pages", pageQuery);
        return "index1.html";
    }
    @GetMapping("/detail")
    public String detail(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "4") Integer pageSize,
                         @RequestParam(value = "pageSize") String keyword,
                        HttpServletRequest request){
        PageQuery<Blog> pageQuery = blogService.pageBlog(pageNumber, pageSize, keyword);
        return "single.html";
    }
}
